package com.houweishi.module.contract.controller;

import com.houweishi.common.annotation.Log;
import com.houweishi.common.core.controller.BaseController;
import com.houweishi.common.core.domain.AjaxResult;
import com.houweishi.common.core.page.TableDataInfo;
import com.houweishi.common.enums.BusinessType;
import com.houweishi.common.utils.poi.ExcelUtil;
import com.houweishi.module.contract.domain.OaContractApproval;
import com.houweishi.module.contract.domain.OaContractApprovalRecord;
import com.houweishi.module.contract.service.IOaContractApprovalService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 法务审批Controller
 * 
 * @author houweishi
 * @date 2023-02-21
 */
@RestController
@RequestMapping("/module/contract")
public class OaContractApprovalController extends BaseController
{
    Logger logger = LoggerFactory.getLogger("OaContractApprovalController.class");
    @Autowired
    private IOaContractApprovalService oaContractApprovalService;

    /**
     * 查询法务审批列表
     */
    @PreAuthorize("@ss.hasPermi('module:contract:list')")
    @GetMapping("/list")
    public TableDataInfo list(OaContractApproval oaContractApproval)
    {
        startPage();
        List<OaContractApprovalRecord> list =
                oaContractApprovalService.selectOaContractApprovalRecordList(oaContractApproval);
        return getDataTable(list);
    }

    /**
     * 导出法务审批列表
     */
    @PreAuthorize("@ss.hasPermi('module:contract:export')")
    @Log(title = "法务审批", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OaContractApproval oaContractApproval)
    {
        List<OaContractApproval> list = oaContractApprovalService.selectOaContractApprovalList(oaContractApproval);
        ExcelUtil<OaContractApproval> util = new ExcelUtil<OaContractApproval>(OaContractApproval.class);
        util.exportExcel(response, list, "法务审批数据");
    }

    /**
     * 获取法务审批详细信息
     */
    @PreAuthorize("@ss.hasPermi('module:contract:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(oaContractApprovalService.selectOaContractApprovalById(id));
    }

    /**
     * 新增法务审批
     */
    @PreAuthorize("@ss.hasPermi('module:contract:add')")
    @Log(title = "法务审批", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OaContractApproval oaContractApproval)
    {
        try {
            return oaContractApprovalService.insertOaContractApproval(oaContractApproval);
        } catch (Exception e) {
            logger.error("新增法务审批失败",e);
            return AjaxResult.error(e.getMessage());
        }
    }

    /**
     * 修改法务审批
     */
    @PreAuthorize("@ss.hasPermi('module:contract:edit')")
    @Log(title = "法务审批", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OaContractApproval oaContractApproval)
    {
        return toAjax(oaContractApprovalService.updateOaContractApproval(oaContractApproval));
    }

    /**
     * 删除法务审批
     */
    @PreAuthorize("@ss.hasPermi('module:contract:remove')")
    @Log(title = "法务审批", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(oaContractApprovalService.deleteOaContractApprovalByIds(ids));
    }
}
